/*
 * @Author: your name
 * @Date: 2022-03-18 21:40:45
 * @LastEditTime: 2022-03-20 14:37:48
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \driving\src\auth\auth.service.ts
 */
import { HttpService, Injectable } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
import { User } from 'src/user/entities/user.entity';
import { UserService } from 'src/user/user.service';
import { CreateAuthDto } from './dto/create-auth.dto';
import { UpdateAuthDto } from './dto/update-auth.dto';

@Injectable()
export class AuthService {
  constructor(
    private jwtService: JwtService,
    private userService: UserService,
    private httpService: HttpService,
  ) {}
  async getUser(user) {
    return await this.userService.findOne(user.id);
  }
  createToken(user:Partial<User>){
    return this.jwtService.sign(user)
  }

  async login(user:Partial<User>){
    const token = this.createToken({
      id: user.id,
      username: user.username,
    });
    return { token:token} ;
  }
}
